package com.zjy.pojo;

import lombok.Data;
import org.springframework.http.HttpStatus;

@Data
public class ResponseResult<T> {
    private int code;
    private String message;
    private T data;

    public ResponseResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseResult<T> success(T data) {
        if (data instanceof String) {
            return new ResponseResult<>(HttpStatus.OK.value(), (String) data, null);
        } else {
            return new ResponseResult<>(HttpStatus.OK.value(), "success", data);
        }
    }

    public static <T> ResponseResult<T> error(int code, String message) {
        return new ResponseResult<>(code, message, null);
    }
}